/*
 * The MIT License
 *
 * Copyright 2011 Roman Yakovenko <erelus@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.stego.image;

/**
 * @author Roman Yakovenko <erelus@gmail.com>
 */
public class Pixel {

    protected int alpha;
    protected int red;
    protected int green;
    protected int blue;

    public Pixel() {
        this.alpha = (byte) 0xFF;
        this.red = 0;
        this.green = 0;
        this.blue = 0;
    }

    public Pixel(int pixel) {
        this.alpha =  ((pixel & 0xFF000000) >> 24 & 0xFF);
        this.red =  ((pixel & 0x00FF0000) >> 16);
        this.green =  ((pixel & 0x0000FF00) >> 8);
        this.blue =  (pixel & 0x000000FF);
    }

    public int getPixel() {
        return ((this.alpha & 0xFF) << 24)
                | ((this.red & 0xFF) << 16)
                | ((this.green & 0xFF) << 8)
                | (this.blue & 0xFF);
    }

    public int getAlpha() {
        return alpha;
    }

    public int getBlue() {
        return blue;
    }

    public int getGreen() {
        return green;
    }

    public int getRed() {
        return red;
    }

    public void setAlpha(int alpha) {
        if (alpha < 0 || alpha > 255) {
            alpha = 0;
        }
        this.alpha = alpha;
    }

    public void setBlue(int blue) {
        if (blue < 0) {
            blue = 0;
        }

        if (blue > 255) {
            blue = 255;
        }
        this.blue =  blue;
    }

    public void setGreen(int green) {
        if (green < 0) {
            green = 0;
        }

        if (green > 255) {
            green = 255;
        }
        this.green = green;
    }

    public void setRed(int red) {
//        if (red < 0) {
//            red = 0;
//        }
//        if (red > 255) {
//            red = 255;
//        }
        this.red =  red;
    }
}
